<?php

	$this->Html->script(array('flexigrid.pack','jquery.maskedinput-1.2.2.min','maskinput','somente-numeros'), false);
	$this->Html->css('flexigrid', null, array('inline' => false));
	
	$matricula_id = $this->request->data['Matricula']['id'];
	
	echo '<fieldset><legend>Matrícula do(a) Aluno(a):</legend>';
	echo '<table>';
	echo '<tr><td>Ano:</td><td><b>' . $this->request->data['Matricula']['ano'] . '</b></td></tr>';
	echo '<tr><td>Aluno(a):</td><td><b>' . $this->request->data['Aluno']['nome'] . '</b></td></tr>';
	echo '<tr><td>Série:</td><td><b>' . $this->request->data['TipoSerie']['nome'] . '</b></td></tr>';
	echo '<tr><td>Turma:</td><td><b>' . $this->request->data['Turma']['nome'] . '</b></td></tr>';
	echo '</table>';
	echo '</fieldset>';
	
	echo $this->Form->create('Matricula');
	echo $this->Form->input('id');
	echo $this->Form->input('aluno_id',array('type' => 'hidden'));
	echo $this->Form->input('responsavel_fin_id', array('type' => 'hidden'));
	echo $this->Form->input('responsavel_ped_id', array('type' => 'hidden'));
	echo $this->Form->input('tipo_serie_id', array('type' => 'hidden'));
	echo $this->Form->input('turma_id', array('type' => 'hidden'));
	echo $this->Form->input('ano', array('type' => 'hidden'));
	
	echo '<div style="clear:both"></div>';
	
?>

<div id="tabs">

	<ul>
		<li><a href="#tabs-Matricula">Matrícula</a></li>
		<li><a href="#tabs-Disciplinas">Disciplinas</a></li>
	</ul>
	
	<div id="tabs-Matricula" class="painel_tabs">	
	
		<?php 			
			echo $this->Form->input('responsavel_financeiro_nome', array('type' => 'text', 'label' => __('Responsável Financeiro'), 'class' => 'tamanho50', 'value' => $nome_responsavel_financeiro, 'div' => array('class' => 'required')));
			echo '<div style="clear:both;"></div>'.'<br/>';
			echo $this->Form->input('responsavel_pedagogico_nome', array('type' => 'text', 'label' => __('Responsável Pedagógico'), 'class' => 'tamanho50', 'value' => $nome_responsavel_pedagogico, 'div' => array('class' => 'required')));
			echo '<div style="clear:both;"></div>'.'<br/>';
			echo $this->Form->input('aluno_numero', array('type' => 'text', 'label' => __('Número do Aluno'), 'class' => 'tamanho10', 'maxlength' => 3, 'onKeyPress' => 'return SomenteNumero(event)'));
		?>
	</div>

	<div id="tabs-Disciplinas" class="painel_tabs">	
		<?php include_once 'grid_matricula_disciplinas.ctp'; ?>
	</div>	

</div>

<?php

	echo '<div class="botoes_form">';
	echo $this->Form->button('Salvar', array('type' => 'submit'));
	echo $this->Form->button('Voltar', array('type'=>'button', 'onClick' => "javascript:location='{$this->request->base}/{$this->request->controller}/matriculas'"));
	echo '</div>'; 
	echo $this->Form->end();
	
?>

<script>

	$( "#tabs" ).tabs({cookie: {expires: 1}	});

	$("#MatriculaResponsavelFinanceiroNome").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: '<?php echo $this->Html->url(array('controller' => 'responsaveis', 'action' => 'pesquisar')); ?>',
				dataType: "jsonp",
				data: {
					nome: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							id: item.id,
							value: item.value
						}
					}));
				}
			});
		},
		
		minLength: 3,
		
		select: function( event, ui ) {
			$("#MatriculaResponsavelFinId").val(ui.item.id);
			$("#MatriculaResponsavelFinanceiroNome").val(ui.item.value);

		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	});

	$("#MatriculaResponsavelPedagogicoNome").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: '<?php echo $this->Html->url(array('controller' => 'responsaveis', 'action' => 'pesquisar')); ?>',
				dataType: "jsonp",
				data: {
					nome: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							id: item.id,
							value: item.value
						}
					}));
				}
			});
		},
		
		minLength: 3,
		
		select: function( event, ui ) {
			$("#MatriculaResponsavelPedId").val(ui.item.id);
			$("#MatriculaResponsavelPedagogicoNome").val(ui.item.value);

		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	});	
	
</script>	